package org.aeon.client.view.components.sessionPanel;

import lombok.Getter;
import org.aeon.entity.dto.GroupInfoDto;

import javax.swing.*;
import java.awt.*;

/**
 * @author: MissingAeon
 * @date: 2024/2/20 14:03
 * @description:
 */
@Getter
public class GroupChatPanel extends JPanel {
    final ChatTopPanel topPanel;
    private final ChatRecordPanel recordPanel;
    private final ChatEditorPanel editorPanel;
    private final GroupAnnouncementPanel announcementPanel;
    private final GroupMemberPanel memberPanel;

    public GroupChatPanel() {
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        topPanel = new ChatTopPanel();
        this.add(topPanel);

        this.add(getSeparator(SwingConstants.HORIZONTAL));

        final Box horizontalBox = Box.createHorizontalBox();

        final Box verticalBox1 = Box.createVerticalBox();
        recordPanel = new ChatRecordPanel(new Dimension(500, 400));
        verticalBox1.add(recordPanel);
        // 添加分隔线
        verticalBox1.add(getSeparator(SwingConstants.HORIZONTAL));

        editorPanel = new ChatEditorPanel(new Dimension(500, 240));
        verticalBox1.add(editorPanel);
        horizontalBox.add(verticalBox1);

        // 添加分隔线
        horizontalBox.add(getSeparator(SwingConstants.VERTICAL));

        final Box verticalBox2 = Box.createVerticalBox();

        announcementPanel = new GroupAnnouncementPanel(new Dimension(195, 190));
        verticalBox2.add(announcementPanel);
        // 添加分隔线
        verticalBox2.add(getSeparator(SwingConstants.HORIZONTAL));

        memberPanel = new GroupMemberPanel(new Dimension(195, 450));
        verticalBox2.add(memberPanel);
        horizontalBox.add(verticalBox2);

        this.add(horizontalBox);

        // 相互绑定
        editorPanel.setRecordPanel(recordPanel);
        recordPanel.setEditorPanel(editorPanel);
    }

    private JSeparator getSeparator(int swingConstants) {
        // 分割线
        JSeparator separator = new JSeparator(swingConstants);
        // 设置分隔线的最大尺寸
        switch (swingConstants) {
            case SwingConstants.HORIZONTAL -> separator.setMaximumSize(new Dimension(700, 5));
            case SwingConstants.VERTICAL -> separator.setMaximumSize(new Dimension(5, 650));
        }
        return separator;
    }


    public void fillInData(GroupInfoDto groupInfo) {

        topPanel.load(groupInfo);
        recordPanel.load(groupInfo);
        editorPanel.load(groupInfo);

        announcementPanel.load(groupInfo);

        memberPanel.load(groupInfo);

        recordPanel.setScrollBar(-1);
    }
}
